using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DataAccessLayer
{
    public class DAO_Question_Item_Figure
    {
        public static bool Insert(Object tmp)
        {
            QUESTION_ITEM_FIGURE obj = (QUESTION_ITEM_FIGURE)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@FIGURE_ID", obj.FIGURE_ID));
            _list.Add(new SqlParameter("@ITEM_ID", obj.ITEM_ID));
            _list.Add(new SqlParameter("@ITEM_FIGURE_DESC", obj.ITEM_FIGURE_DESC));

            int n = clsDataAccessHelper.ExecNonQuery("sp_question_item_figure_insert", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static QUESTION_ITEM_FIGURE Select(int id)
        {
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@ITEM_ID", id));

            DataTable table = clsDataAccessHelper.ExecuteQuery("sp_question_item_figure_select", _list);
            if (table != null && table.Rows.Count == 1)
            {
                QUESTION_ITEM_FIGURE obj = new QUESTION_ITEM_FIGURE();
                obj.FIGURE_ID = decimal.Parse(table.Rows[0]["FIGURE_ID"].ToString());
                obj.ITEM_FIGURE_DESC = table.Rows[0]["ITEM_FIGURE_DESC"].ToString();
                obj.ITEM_FIGURE_ID = decimal.Parse(table.Rows[0]["ITEM_FIGURE_ID"].ToString());
                obj.ITEM_ID = decimal.Parse(table.Rows[0]["ITEM_ID"].ToString());
                return obj;
            }
            return null;
        }

        public static bool Update(Object tmp)
        {
            QUESTION_ITEM_FIGURE obj = (QUESTION_ITEM_FIGURE)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@FIGURE_ID", obj.FIGURE_ID));
            _list.Add(new SqlParameter("@ITEM_FIGURE_DESC", obj.ITEM_FIGURE_DESC));
            _list.Add(new SqlParameter("@ITEM_FIGURE_ID", obj.ITEM_FIGURE_ID));
            _list.Add(new SqlParameter("@ITEM_ID", obj.ITEM_ID));

            int n = clsDataAccessHelper.ExecNonQuery("sp_question_item_figure_update", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static bool Delete(Object tmp)
        {
            QUESTION_ITEM_FIGURE obj = (QUESTION_ITEM_FIGURE)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            //_list.Add(new SqlParameter("@FIGURE_ID", obj.FIGURE_ID));
            //_list.Add(new SqlParameter("@ITEM_FIGURE_DESC", obj.ITEM_FIGURE_DESC));
            _list.Add(new SqlParameter("@ITEM_FIGURE_ID", obj.ITEM_FIGURE_ID));
            //_list.Add(new SqlParameter("@ITEM_ID", obj.ITEM_ID));

            int n = clsDataAccessHelper.ExecNonQuery("sp_question_item_figure_delete", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static List<QUESTION_ITEM_FIGURE> LoadAll()
        {
            List<QUESTION_ITEM_FIGURE> _list = new List<QUESTION_ITEM_FIGURE>();
            //call stored getlist here
            return _list;
        }
    }
}
